#include <mytexteditor.h>
#include <QTextStream>
#include <QFile>
#include <iostream>

using namespace std;
#define DEBUG 1

myQTextEdit::myQTextEdit(QWidget *parent):QTextEdit(parent)
{
  QTextEdit qe("myQTextEdit");
}

void  myQTextEdit::loadFile()
{
  /*
  QFile file("todo");
  file.open(QIODevice::WriteOnly);

  QTextStream out(&file);
  out << "test to do" << endl;
  file.close();
  */
 
  QFile file("todo");
  file.open(QIODevice::ReadOnly);
  QTextStream in(&file);
  
  while(!in.atEnd())
    { 
      QString line = in.readLine();  //cout << in.readLine(); doesn't work
      this->insertPlainText("\n");   //line break;
      cout << line.toStdString() << endl;
      this->insertPlainText(line);
    }
  file.close();
  //this->setDocumentTitle(line);  //editor.setDocumentTitle(line);
  //this->setPlainText(line);  //editor.setPlainText(line);
  //this->acceptRichText();  //editor.acceptRichText();
}


void myQTextEdit::saveFile()
{
  QFile file("todo_save");
  file.open(QIODevice::WriteOnly);
  QTextStream out(&file);
  QString context = this->toPlainText();
  #if DEBUG
  cout << context.toStdString() << endl;
  #endif
  out <<  context;
  file.close();
}
